<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/base_user.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <title>管理收货地址</title>
    <script>
        function hit(index){
                var id = $('#radio_'+index).val();  //选择的id
                var  ids = '';
                $('#radio_'+index).prop('checked',true);
                $(".radio1").not("input:checked").each(function (a,o) {
                    if (ids == ''){
                        ids = $(o).val();
                    }else {
                        ids += ','+$(o).val();
                    }
                });
                //ajax对应修改数据
                $.post("{:url('mobile/user_info/edit_default')}",{'id':id,'ids':ids},function (t) {
                    console.log(t);
                        layer.open({content:t.message,skin:'msg',time:3});
                    setTimeout(function () {
                        window.location.reload();
                    }, 1000);

                },'json');
        }

        //删除
        function del(id){
            layer.open({
                content: '您确定要删除此地址吗？'
                ,btn: ['确定', '取消']
                ,yes: function(index){
                    $.post('address_del',{'id':id},function(t){
                        layer.open({content:t.message,skin:'msg',time:2});
                        window.location.reload();
                    });
                    layer.close(index);
                }
            });
        }
    </script>
    <style>
        .wrap-man .center{
            border-bottom:5px solid #F6F6F6;
        }
    </style>
</head>
<body>
<div class="wrap-man">
    <div class="header">
        <p>管理收货地址</p>
        <img src="__STATIC__/img_user/back.png" class="back" onclick="back_url()">
        <span><a href="javascript:create_address();">添加地址</a></span>
    </div>
    <input type="hidden" id="act" value="{:input('act')}"  />
    {volist name='data.memberAddress' id='v'}
    <div class="center">
        <a href="javascript:check_this({$v.id});">
        <p class="name">姓名  <span>{$v.name}</span><span style="margin-left: 10%">{$v.phone}</span></p>
        <p class="address">{$v.area_info}&nbsp;&nbsp;{$v.address}</p>
        </a>
        <div>
            <div class="pri"><input type="radio" value="{$v.id}" name="radio-1-set" id="radio_{$key}" class="radio1" {eq name="v.status" value="1"}checked{/eq} /><label onclick="hit({$key})">设为默认</label></div>
            <div class="operate">
                <a href="javascript:edit({$v.id});" style="overflow: hidden;"><img src="__STATIC__/img_user/sh-binaji.png"><span style="margin-right: 20px;">编辑</span></a>
                <a href="javascript:del({$v.id});" style="overflow: hidden;"><img src="__STATIC__/img_user/sh-shanchu.png"><span>删除</span></a>
            </div>
        </div>
    </div>
    {/volist}
</div>
{include file="public/src"  /}
<script>
    //订单||积分选择此地址
    function check_this(id) {
        var type = $('#act').val();
        if (type == 'order'){
            var url = sessionStorage.getItem('order_yes_url');
            if (url.indexOf('address_id=') > -1){
                var urlArr = url.split('&');
                for (var i=0 ; i<urlArr.length; i++){
                    if (urlArr[i].indexOf('address_id=') > -1){
                        urlArr[i] = 'address_id='+id;
                    }
                }
                url = urlArr.join('&');
            }else{
                url = url+"&address_id="+id;
            }
            window.location.href = url;
        }else if (!"{:input('?act')}" && sessionStorage.getItem('exchange_url') !== null){
            window.location.href = sessionStorage.getItem('exchange_url')+"&address_id="+id;
        }
    }
    //添加地址
    function create_address(){
        var type = $('#act').val();
        if (type == 'order'){
            window.location.href = "{:url('mobile/user_info/create_address')}?act=order";
        }else{
            window.location.href = "{:url('mobile/user_info/create_address')}";
        }

    }
    //页面返回路径
    function back_url(){
        var act = $('#act').val();
        if (act == 'order'){   //如果是订单页过来的返回订单页,否则返回个人信息
            window.location.href = sessionStorage.getItem('order_yes_url');
        }else if ( sessionStorage.getItem('exchange_url') !== null ){  //积分兑换
            window.location.href = sessionStorage.getItem('exchange_url');
        }else if (act == 'auction'){
            window.location.href = "{:url('mobile/auction/order')}";
        }else if (act='my'){
            window.location.href = "{:url('mobile/user_info/my_shop_index')}";
        }else{
            window.location.href = "{:url('mobile/user_info/self_information')}";
        }
    }
    //修改地址
    function edit(id) {
        var type = $('#act').val();
        if (type == 'order'){
            window.location.href = "{:url('mobile/user_info/edit_address')}?act=order&id="+id;
        }else{
            window.location.href = "{:url('mobile/user_info/edit_address')}?id="+id;
        }
    }

</script>
</body>
</html>